<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
 * 
 * @author yangxc
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
    <title>客户端授权管理</title>
    <script src="${contextPath}/resources/jquery-1.8.3.min.js"></script>
</head>
<body>
<h2></h2>

<div class="pull-right">
    <a href="${contextPath}/clients/register" class="btn btn-success btn-sm">添加客户端</a>
</div>
<form action="${contextPath}/clients/query" class="form-inline">
    <div class="form-group">
        <input type="text" class="form-control" placeholder="" name="client_id"
               value=""/>
    </div>
    <button type="submit" class="btn btn-default">查询</button>

</form>
<br/>
<div ng-app="myApp" ng-controller="formCtrl">
<table class="table table-bordered table-hover table-striped">
    <thead>
    <tr>
        <th>clientId</th>
        <th>clientSecret</th>
        <th>绑定IP</th>
        <th>公司名</th>
        <th>应用名</th>
        <th>联系人</th>
        <th>联系电话</th>
        <th>Email</th>
        <th>创建时间</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${clientsList}" var="clients">
        <tr>
            <td>${clients.clientId}</td>
            <td>${clients.clientSecret}</td>
            <td>${clients.boundIp}</td>
            <td>${clients.company}</td>
            <td>${clients.appName}</td>
            <td>${clients.contacts}</td>
            <td>${clients.tel}</td>
            <td>${clients.email}</td>
            <td>${clients.createTime}</td>
            <td>
                <div id="button_${clients.clientId}">
                <c:if test="${clients.archived==false}">
                    <button type="button" class="btn btn-default" onclick="disableOrEnable('${clients.clientId}',true);">禁用</button>
                </c:if>
                <c:if test="${clients.archived==true}">
                    <button type="button" class="btn btn-default" onclick="disableOrEnable('${clients.clientId}',false);">启用</button>
                </c:if>
                </div>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
</div>
<script>

    function disableOrEnable(client_id,flag){
        var url ="${contextPath}/clients/disable?client_id="+client_id;
        if(flag){
            url ="${contextPath}/clients/enable?client_id="+client_id;
        }
        $.get(url,null,function(result){
            if(flag){
                $("#button_"+client_id).html("<button type=\"button\" class=\"btn btn-default\" onclick=\"disableOrEnable('"+client_id+"',true);\">启用</button>");
            }else{
                $("#button_"+client_id).html("<button type=\"button\" class=\"btn btn-default\" onclick=\"disableOrEnable('"+client_id+"',true);\">禁用</button>");
            }
        });

    }
</script>
</body>
</html>